package service.impl;

import dao.UserDao;
import dao.impl.UserDaoImpl;
import po.User;
import service.UserService;
import util.Constant;
import util.MD5Util;

public class UserServiceImpl implements UserService {
    @Override
    public boolean checkResgist(String phone) throws Exception {

        UserDao dao = new UserDaoImpl();
        int count=dao.getNumOfPhone(phone);

        return count == 0? Constant.PHONE_NO_REGISTE :Constant.PHONE_ALREADY_REGISTE;
    }

    @Override
    public boolean addUser(User user) throws Exception {
       // 1 生成uUID作为主键
        String id= java.util.UUID.randomUUID().toString().replace("-","");
        user.setId(id);
        // 2 密码散列
       String md5Pwd= MD5Util.makePassword(user.getPwd());
       user.setPwd(md5Pwd);

        UserDao dao = new UserDaoImpl();

        return  dao.addUser(user);
    }


}
